﻿/**
 * @Description 基础框架服务配置
 *@Author  guoyanfei
 */
var serviceUrl = "/gdp";//服务地址
var serviceId = "";//服务ID

$(function(){
    var Request = GetRequest();
    serviceId = Request["serviceID"];

})

//获取Url参数
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串 
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

/*$.ajaxSetup( {  
    //设置ajax请求结束后的执行动作  
    complete :   
    function(XMLHttpRequest, textStatus) {  
        // 通过XMLHttpRequest取得响应头，sessionstatus  
        var sessionstatus = XMLHttpRequest.getResponseHeader("SESSIONSTATUS"); 
	console.info(XMLHttpRequest.SESSIONSTATUS);
        if (XMLHttpRequest.status  == 401) {  
            var win = window;  
            while (win != win.top){  
                win = win.top;  
            }  
                win.location.href= "http://127.0.0.1:8080/frame-main-web/authorization/index?pid=1";  
        }  
    }  
}); */

// here is handle response mode result
// if response mode is single mode , create respose data of pageable
// if resposne mode is other , directory return
                // return {
                //     "total": res.data.total,//总页数
                //     "rows": res.data.rows   //数据
                // };

// pageable and response mode

var isPageFormat = true;

function handleResponseResult(response){
    console.log("handle response result response and isPageFormat", response, isPageFormat)
    if(isPageFormat){
        return handleResponseModeResultForPageableVo(response);
    }

    return handleResponseModeResultForNoPageable(response);
}

function handleResponseModeResultForPageableVo(response){
    // here is question , result data not here
    // here is return response.data
    if(response.result != 0){
       // alert(response.message)
        return {
                "total": 0,//总页数
                "rows": null   //数据
        };
        return;
    }

    if(response.responseMode === "SingleMode"){
        // here create pageable result
        var rows = [];
        var data = response.data;
        if(data != ''){
            rows.push(data)
        }

        var pageableVo = {
            "total": 1,
            "rows": rows
        }
        return pageableVo;
    }

    return {
        "total": response.data.total,//总页数
        "rows": response.data.rows   //数据
    };
};

// here function handle for No pageable object
function handleResponseModeResultForNoPageable(response){
    if(response.responseMode === 'SingleMode'){
        var rows = [];
        var data = response.data;
        if(data != ''){
            rows.push(data)
        }

        return rows;
    }

    return response.data.rows;
}

// copy to clipboard
function updateClipboard(newClip) {
    console.log("luowen newClip", newClip)
  navigator.clipboard.writeText(newClip).then(() => {
    /* clipboard successfully set */
  }, () => {
    /* clipboard write failed */
  });
}
